﻿<custom:TabPageControl x:Class="MIXer.Views.DownloaderView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:custom="clr-namespace:MIXer.Customization"
             xmlns:cal="http://www.caliburnproject.org">
    
    <ContentControl.Resources>
        <DataTemplate x:Key="SessionsListTemplate">
            <Border Padding="10 10 10 10" cal:Bind.Model="{Binding}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <StackPanel Orientation="Horizontal" Grid.Row="0">
                        <CheckBox x:Name="IsSelected" VerticalAlignment="Center" 
                                                      cal:Message.Attach="[Event Checked] = [Action FileCheckChanged($dataContext)]; [Event Unchecked] = [Action FileCheckChanged($dataContext)]">
                            <CheckBox.Style>
                                <Style TargetType="CheckBox">
                                    <Setter Property="Visibility" Value="Visible" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Downloading}" Value="True">
                                            <Setter Property="Visibility" Value="Collapsed" />
                                        </DataTrigger>
                                        <DataTrigger Binding="{Binding Downloaded}" Value="True">
                                            <Setter Property="Visibility" Value="Collapsed" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </CheckBox.Style>
                        </CheckBox>
                        <TextBlock x:Name="Session_Title" Margin="5 0 5 0" VerticalAlignment="Center" />
                        <TextBlock Text="with" Margin="0 0 5 0" />
                        <TextBlock x:Name="Session_Author" VerticalAlignment="Center" Margin="0 0 5 0" />
                        <TextBlock Text="[" />
                        <TextBlock x:Name="Session_FriendlyLength" VerticalAlignment="Center" />
                        <TextBlock Text="]" Margin="0 0 5 0" />
                        <Image Source="/Images/tick.png">
                            <Image.Style>
                                <Style TargetType="Image">
                                    <Setter Property="Visibility" Value="Collapsed" />
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Downloaded}" Value="True">
                                            <Setter Property="Visibility" Value="Visible" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Image.Style>
                        </Image>
                    </StackPanel>

                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Grid.Row="1">
                        <StackPanel.Style>
                            <Style TargetType="StackPanel">
                                <Setter Property="Visibility" Value="Collapsed" />
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Downloading}" Value="True">
                                        <Setter Property="Visibility" Value="Visible" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </StackPanel.Style>
                        <ProgressBar Height="15" Width="400" Margin="0 5 0 0" Value="{Binding Progress}" HorizontalContentAlignment="Left" />
                        <TextBlock x:Name="Progress" Margin="5 5 0 5" FontWeight="Bold" VerticalAlignment="Center" />
                        <TextBlock Text="%" FontWeight="Bold" VerticalAlignment="Center" />
                        <TextBlock Text="/" Margin="5 0 5 0" FontWeight="Bold" VerticalAlignment="Center" />
                        <TextBlock x:Name="BytesDownloadedDescription" FontWeight="Bold" VerticalAlignment="Center" />
                        <TextBlock Text="(" Margin="5 0 0 0" FontWeight="Bold" VerticalAlignment="Center" />
                        <TextBlock x:Name="SpeedDescription" FontWeight="Bold" VerticalAlignment="Center" />
                        <TextBlock Text=")" FontWeight="Bold" VerticalAlignment="Center" />
                        <Button Content="Cancel" Padding="10 5 10 5" Margin="5 5 5 5" cal:Message.Attach="[Event Click] = [Action Cancel($dataContext)]"/>
                    </StackPanel>
                </Grid>
            </Border>
        </DataTemplate>
    </ContentControl.Resources>
    
    <DockPanel LastChildFill="True">
        <Grid DockPanel.Dock="Top" Margin="10 10 10 10">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <!-- ROW 0 -->
            <TextBlock Text="Select event:" VerticalAlignment="Center" Padding="10 5 10 5" Grid.Column="0" Grid.Row="0" />
            <ComboBox x:Name="Events" Margin="5 5 5 5" Grid.Row="0" Grid.Column="1">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Border Padding="2 2 2 2">
                            <TextBlock Text="{Binding EventFriendlyName}" />
                        </Border>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <Button x:Name="RefreshFiles" Content="Refresh" Padding="10 5 10 5" Margin="5 5 5 5" Grid.Column="4" Grid.Row="0" />

            <!-- ROW 1 -->
            <TextBlock Text="Download" VerticalAlignment="Center" Padding="10 5 10 5" Grid.Column="0" Grid.Row="1" />
            <ComboBox x:Name="Feeds" Margin="5 5 5 5" Grid.Column="1" Grid.Row="1">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Border Padding="2 2 2 2">
                            <TextBlock Text="{Binding Description}" />
                        </Border>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <TextBlock Text="To" VerticalAlignment="Center" Padding="10 5 10 5" Grid.Column="2" Grid.Row="1" />
            <TextBox x:Name="FolderLocation" Margin="5 5 5 5" Grid.Column="3" Grid.Row="1" />
            <Button x:Name="OpenFolderDialog" Content="Browse" Padding="10 5 10 5" Margin="5 5 5 5" Grid.Column="4" Grid.Row="1" />
        </Grid>

        <Grid DockPanel.Dock="Bottom" Margin="10 10 10 10">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <StackPanel Orientation="Horizontal" Grid.Column="0">
                <TextBlock Text="Name format:" Padding="10 5 10 5" VerticalAlignment="Center" />
                <TextBox x:Name="NameFormat" Margin="5 5 5 5" Width="120" />
                <TextBlock Text="Available tokens:" Padding="10 5 10 5" VerticalAlignment="Center" />
                <TextBlock x:Name="AvailableTokens" Margin="5 5 5 5" VerticalAlignment="Center" FontWeight="Bold" />
            </StackPanel>

            <StackPanel Orientation="Horizontal" Grid.Column="1">
                <TextBlock x:Name="CurrentSpeed" Padding="10 5 10 5" Margin="5 5 5 5" FontWeight="Bold" VerticalAlignment="Center" />
                <Button x:Name="DeSelectAll" Content="Deselect all" Padding="10 5 10 5" Margin="5 5 5 5" />
                <Button x:Name="SelectAll" Content="Select all" Padding="10 5 10 5" Margin="5 5 5 5" />
                <Button x:Name="DownloadFiles" Content="Start download" Padding="10 5 10 5" Margin="5 5 5 5" />
            </StackPanel>
        </Grid>

        <DockPanel Margin="10 10 10 10" LastChildFill="True">
            
            <DockPanel DockPanel.Dock="Top" LastChildFill="True">
                <TextBlock Text="Search for:" Padding="10 5 10 0" VerticalAlignment="Center" DockPanel.Dock="Left" />
                <TextBox x:Name="SearchText" Margin="0 5 10 0" cal:Message.Attach="SearchTextChanged($text)" />
            </DockPanel>

            <TabControl Margin="10 5 10 10">
                <TabItem Header="To Download">
                    <ListBox x:Name="ToDownloadFiles" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemTemplate="{StaticResource SessionsListTemplate}" />
                </TabItem>
                <TabItem Header="Downloading">
                    <ListBox x:Name="DownloadingFiles" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemTemplate="{StaticResource SessionsListTemplate}" />
                </TabItem>
                <TabItem Header="Downloaded">
                    <ListBox x:Name="DownloadedFiles" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemTemplate="{StaticResource SessionsListTemplate}" />
                </TabItem>
            </TabControl>
        </DockPanel>
    </DockPanel>
</custom:TabPageControl>
